# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 添加子目录
add_subdirectory(jsi_executor)
add_subdirectory(utils)
add_subdirectory(bridge)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/jsi build)

# 定义一个变量来存储源文件
set(ENGINE_SOURCES
  $<TARGET_OBJECTS:jsi>
  $<TARGET_OBJECTS:jsiexecutor>
  $<TARGET_OBJECTS:utils>
  $<TARGET_OBJECTS:bridge>
)

# 根据 VM_TYPE 的值来决定要添加哪些源文件
if(VM_TYPE STREQUAL "QJS")
  add_subdirectory(vm/qjs)
  list(APPEND ENGINE_SOURCES $<TARGET_OBJECTS:quickjs_jsi>)
elseif(VM_TYPE STREQUAL "JSVM")
  add_subdirectory(vm/jsvm)
  list(APPEND ENGINE_SOURCES $<TARGET_OBJECTS:jsvm_executor_common>)
elseif(VM_TYPE STREQUAL "JSC")
  add_subdirectory(vm/jsc)
  list(APPEND ENGINE_SOURCES $<TARGET_OBJECTS:jsc_executor_common>)
endif()

# 创建库目标并将源文件添加进去
add_library(engine STATIC ${ENGINE_SOURCES})